#define  _CRT_SECURE_NO_WARNINGS
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
 // class Solution {
 // public:
 //     TreeNode* pruneTree(TreeNode* root) {
 //         if(root == nullptr) return nullptr;
 //         TreeNode* pL = pruneTree(root->left);
 //         TreeNode* pR = pruneTree(root->right);
 //         if(!pL && !pR && !root->val) root = nullptr;
 //         if(!pL) root->left = nullptr;
 //         if(!pR) root->right = nullptr;
 //         return root;
 //     }
 // };
class Solution {
public:
    TreeNode* pruneTree(TreeNode* root) {
        if (root == nullptr) return nullptr;
        root->left = pruneTree(root->left);
        root->right = pruneTree(root->right);
        if (!root->left && !root->right && !root->val) root = nullptr;
        return root;
    }
};